$(document).ready(function()
{
	var options = {
		target: '#response_div',
		beforeSubmit: preRequest,
		success: postResponse
	};
	$('#vehicle_form').ajaxForm(options);
	aClick();
	aConfirm();
});

function aConfirm()
{
	$('a[name=vehicle_del]').confirm({
		msg: '¿Está seguro?<br />',
		timeout: 10000,
		dialogShow: 'fadeIn',
		buttons: {
			ok: 'Sí',
			cancel: 'No',
			wrapper: '<button></button>',
			separator: '  '
		}
	});
}

function aClick()
{
	$('a[name=vehicle_del]').click(function(event)
	{
		$('#show_vehicles').html('Espere por favor...');
		$.get($(this).attr('href'), function(data){
			$('#show_vehicles').load(
				$('#vehicle_form').attr('action'),
				{ sf_method: 'get' },
				function(){
					aClick();
					aConfirm();
				}
			);
		});
		return false;
	});
}

function preRequest(formData, jqForm, options)
{
	$('#vehicle_form_div').hide();
	$('#loader_div').show();
	return true;
}

function postResponse(responseText, statusText, xhr, $form)
{
	$('#loader_div').hide();
	$('#response_div').show();
	$('#show_vehicles').html('Espere por favor...');
	$('#show_vehicles').load(
		$('#vehicle_form').attr('action'),
		{ sf_method: 'get' },
		function(){
			aClick();
			aConfirm();
		}
	);
}
